The CASE Statement
The VectorScript CASE statement lets you specify a list of alternative statements to be executed, associating a constant with each statement to identify it. When the CASE statement is executed it evaluates the controlling expression, and if the result matches one of the constants, it then executes the associated statement. An optional OTHERWISE clause allows a different statement to be executed if no other option was selected from the list of constants.
The general syntax for a CASE statement is:
 
The control expression may evaluate to an INTEGER, CHAR, or BOOLEAN value. For example:
 
The variable j evaluates to an INTEGER value, and this value is compared to the list of constants in the CASE statement. In the example, the value of j falls outside of the listed constants, so the OTHERWISE clause is executed.
CASE statements provide some flexibility when specifying constants. For instance, there may be applications of the CASE statement where several cases will need to execute the same code. Rather than use redundant options, the CASE statement lets you specify a comma delimited list of constants for a single CASE option:
 
Should the control expression evaluate to any of the values in the list, the associated statement will be executed.
For longer contiguous lists of constant values, the CASE statement also supports the use of ranges within the CASE statement constant specification. These ranges specify a contiguous list of constant values to be associated with a statement to be executed:
 
Ranges and comma delimited lists may be mixed for further flexibility in associating constants with an executable statement:
 
In the example, it can be seen that the available methods of specifying CASE statement constants provide the ability to specify complex options for branching in a very concise format. Ranges and lists also work with the other supported constant types:
 
Like other statements, CASE statements can also support the use of compound statements as the controlled statement to be executed. Extending this concept, it is also possible to create nested CASE statements to handle even more complex branching in scripts:
 
Some cautions to be observed when using CASE statements:
*
Constant values in the CASE statement must have the same type as the value of the controlling expression.
*

Statements : Conditional Statements : The CASE Statement

Nemetschek NA
Phone: 410.290.5114
Fax: 410.290.8050